Skip to content

Use a separate DB for worker jobs (LG-4905)#5275

Merged
zachmargolis merged 17 commits intomainfrom
margolis-worker-separate-db
Aug 23, 2021
Merged

Use a separate DB for worker jobs (LG-4905)#5275
zachmargolis merged 17 commits intomainfrom
margolis-worker-separate-db

Conversation

@zachmargolis
Copy link
Copy Markdown
Contributor

@zachmargolis zachmargolis commented Aug 9, 2021

(Do not merge until https://github.com/18F/identity-devops/pull/3689 is deployed)

Builds on top of

Starting with this PR, we have two schema.rbs

  1. The first is the primary/default one (that we all know and love)
  2. The newer one is just for this second DB, and it comes with its own ActiveRecord::Base class

Comment thread db/primary_migrate/20210809203128_drop_good_jobs_main_database.rb Outdated
Comment on lines +1 to +2
# same as 20210804180216_create_good_jobs.rb but runs in the worker database
class CreateGoodJobsSeparateDatabase < ActiveRecord::Migration[5.2]
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

note in this one it's in db/worker_jobs_migrate instead of db/migrate or db/primary_migrate

Comment thread config/database.yml
development:
primary:
<<: *defaults
migrations_paths: db/primary_migrate
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the default is db/migrate but specifying this makes sure we don't run the old migrations in the jobs-only DB, complete separation of DBs

Base automatically changed from margolis-read-replica-connections to main August 11, 2021 18:02
Comment thread db/schema.rb
Comment on lines 74 to 76
t.integer "user_id", null: false
t.string "encrypted_code", default: "", null: false
t.string "code_fingerprint", default: "", null: false
t.string "encrypted_code", default: "", null: false
t.datetime "used_at"
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is just from doing a full drop/recreat, basically a true-up of this file

@@ -0,0 +1,7 @@
# rubocop:disable Rails/ApplicationRecord
class WorkerJobApplicationRecord < ActiveRecord::Base
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

do we need coverage here?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this class is actually used, the GoodJob::Job dynamically subclasses it, however that may be set up before the code coverage is set up

If this class was not used, GoodJob would look in the wrong DB for its table

@zachmargolis
Copy link
Copy Markdown
Contributor Author

  • confirmed with @pauldoomgov our Dbs are set up through staging correctly
  • admin merging to get around code climate coverage issues

@zachmargolis zachmargolis merged commit 4adbfa0 into main Aug 23, 2021
@zachmargolis zachmargolis deleted the margolis-worker-separate-db branch August 23, 2021 22:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants